package com.xique.park.controller.client.web.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.park.controller.client.web.bean.domain.ClientUser;
import com.xique.park.controller.client.web.mapper.ClientUserMapper;
import com.xique.park.controller.client.web.service.service.IClientUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 岗亭用户中间Service业务层处理
 *
 * @author caogq
 * @date 2021-07-22
 */
@Service
public class ClientUserServiceImpl extends ServiceImpl<ClientUserMapper, ClientUser> implements IClientUserService
{
    @Autowired
    private ClientUserMapper clientUserMapper;

    /**
     * 查询岗亭用户中间
     *
     * @param clientId 岗亭用户中间ID
     * @return 岗亭用户中间
     */
    @Override
    public ClientUser selectClientUserById(Long clientId)
    {
        return clientUserMapper.selectById(clientId);
    }

    /**
     * 查询岗亭用户中间列表
     *
     * @param clientUser 岗亭用户中间
     * @return 岗亭用户中间
     */
    @Override
    public List<ClientUser> selectClientUserList(ClientUser clientUser)
    {
        QueryWrapper<ClientUser> wrapper = new QueryWrapper<>();
        wrapper.eq("sys_user_id", clientUser.getSysUserId());
        return clientUserMapper.selectList(wrapper);
    }

    @Override
    public ClientUser selectOne(ClientUser clientUser) {
        QueryWrapper<ClientUser> wrapper = new QueryWrapper<>();
        if (null != clientUser.getSysUserId()) {
            wrapper.eq("sys_user_id", clientUser.getSysUserId());
        }
        if (null != clientUser.getClientId()) {
            wrapper.eq("client_id", clientUser.getClientId());
        }
        return clientUserMapper.selectOne(wrapper);
    }

    /**
     * 新增岗亭用户中间
     *
     * @param clientUser 岗亭用户中间
     * @return 结果
     */
    @Override
    public int insertClientUser(ClientUser clientUser)
    {
        return clientUserMapper.insert(clientUser);
    }

    /**
     * 修改岗亭用户中间
     *
     * @param clientUser 岗亭用户中间
     * @return 结果
     */
    @Override
    public int updateClientUser(ClientUser clientUser)
    {
        QueryWrapper<ClientUser> wrapper = new QueryWrapper<>();
        if (null != clientUser.getSysUserId()) {
            wrapper.eq("sys_user_id", clientUser.getSysUserId());
        }
        if (null != clientUser.getClientId()) {
            wrapper.eq("client_id", clientUser.getClientId());
        }
        return clientUserMapper.update(clientUser, wrapper);
    }

    /**
     * 批量删除岗亭用户中间
     *
     * @param clientIds 需要删除的岗亭用户中间ID
     * @return 结果
     */
    @Override
    public int deleteClientUserByIds(Long[] clientIds)
    {
        return clientUserMapper.deleteBatchIds(Arrays.asList(clientIds));
    }

    @Override
    public int deleteBatchClientUserList(List<ClientUser> list) {
        return clientUserMapper.deleteBatchClientUserList(list);
    }

    /**
     * 删除岗亭用户中间信息
     *
     * @param clientUser 岗亭用户中间
     * @return 结果
     */
    @Override
    public int deleteClientUser(ClientUser clientUser)
    {
        QueryWrapper<ClientUser> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", clientUser.getUserId()).eq("client_id", clientUser.getClientId());
        return clientUserMapper.delete(wrapper);
    }

    @Override
    public int updateSysUserId(List<ClientUser> list) {
        return clientUserMapper.updateSysUserId(list);
    }
}
